package com.wlr.blog.web.common.utils;

import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.ObjectUtils;

/**
 * @author lrwang
 * @version 1.0
 * @date 2022/11/16 10:37
 */
public class PageUtil {
    /**
     * 当前记录起始索引
     */
    public static final String PAGE_NUM = "pageNum";
    /**
     * 每页显示记录数
     */
    public static final String PAGE_SIZE = "pageSize";
    /**
     * 排序列
     */
    public static final String ORDER_BY_COLUMN = "orderByColumn";
    /**
     * 排序方式
     * desc或者asc
     */
    public static final String IS_ASC = "isAsc";

    public static void startPage() {
        Integer pageNum = ServletUtils.getParameterToInt(PAGE_NUM);
        Integer pageSize = ServletUtils.getParameterToInt(PAGE_SIZE);
        String order = ServletUtils.getParameter(ORDER_BY_COLUMN);
        if (ObjectUtils.isNotEmpty(pageNum) && ObjectUtils.isNotEmpty(pageSize)) {
            PageHelper.startPage(pageNum, pageSize, order);
        }
    }
}
